<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
class UserController extends CommonController {
 
    	
  //===================================产品订单

    public function index() {

        if(IS_POST){
                    $username=trim(I('post.username'));
             
                          $map['phone']=array('like','%'.$username.'%');
                  $count = M('user')->where($map)->count();
 
        $Page =new \Think\Page($count,20);
        $Page -> setConfig('first','首页');
        $Page -> setConfig('last','末页');
        $Page -> setConfig('prev','上一页');
        $Page -> setConfig('next','下一页');
        $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END% </div> ');

         
        $show = $Page->show();
       
            $this->assign("pageCount",$count);
        $this->assign("page",$show);
$user1=M('user')->where($map)->limit($Page->firstRow.','.$Page->listRows)->select();

$this->assign("user",$user1);

        }else{

           $count = M('user')->count();
  
        $Page =new \Think\Page($count,20);
        $Page -> setConfig('first','首页');
        $Page -> setConfig('last','末页');
        $Page -> setConfig('prev','上一页');
        $Page -> setConfig('next','下一页');
        $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END% </div> ');

         
        $show = $Page->show();
       

        $this->assign("page",$show);
$user=M('user')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

      $this->assign("pageCount",$count);
      $this->assign('user',$user);}
    	$this->display();
    }
      
   
    public function addtype(){
        if(IS_POST){
            $data['name']=I('post.name');
        


            if(M('_type')->add($data)){
                $this->success('添加分类成功',U('/index'));
                exit();
            }else{
                $this->success('添加分类失败',U('/index'));
                exit();
            }
        }






        $this->display();
    }

    public function add(){
        $sh=M('_type');
        $shi=$sh->select();
        $this->assign('shi',$shi);


        if(IS_POST){
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     553145728 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
                $upload->savePath  =     ''; // 设置附件上传（子）目录
                // 上传文件
                $info   =   $upload->upload();
                if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{// 上传成功
                    $data["pic"]=$info["pic"]["savepath"].$info["pic"]["savename"];
                  
                }

                $data['create_time'] = time();
                $data['title']=I('post.title');
                // $data['cat_id']=I('post.type');
                $data['intro']=htmlspecialchars_decode(I('post.intro'));
                    

            if(M('')->add($data)){

                $this->success('添加资讯成功',U('/index'));
                exit();
                }else{

                $this->success('添加资讯失败',U('/index'));
                exit();
            }
         
        }

        $this->display();
    }



    public function update(){
        if(IS_POST){
            $data=I('post.');
             $id1=$data['id'];
            $data['content']=implode(',', $data['qx']);
           $data['linian']=implode(',', $data['ks']);
            if(M('user')->where('id='.$id1)->save($data)){
                // $this->success('分配成功',U('User/index'));
                $this->redirect('User/index');
            }else{
                $this->error('分配失败',U('User/index'));
            }

        }else{
   
            $id=I('get.id');
   
           $m=M('user')->where('id='.$id)->find();
           $m['content']=explode(',', $m['content']);
           $m['linian']=explode(',', $m['linian']);
           $quanxian=M('category')->where('pid=0')->select();
           $kuanshi=M('kuanshi')->select();
             $this->data=$m;
           $this->assign('quanxian',$quanxian);
        $this->assign('kuanshi',$kuanshi);
          $this->display(); 
       }

          
        }











 
    


    //批量删除信息
    public function del(){

        $ids = $_POST['id'];

        $str="('".implode("','",$ids)."')";
      

        if (M("user")->where("id in ".$str)->delete()) {
            
            $this->redirect('User/index');
        } else {
            $this->success('删除失败');
        }
    }


      


         public function lider(){
        $lider = M('_type');
        $list = $lider->select();
        $this->assign('list',$list);



        $this->display();
     }



     public function fenlei() {

            $id=I('get.id');
            $zi=M('_type');
            $map['id']=$id;



            $info=$zi->where($map)->find();
          
        


            $this->assign('info',$info);
    
  
      
        if (IS_POST) {
           
            $data=I('post.');

            $id=I('get.id');
            if(M('_type')->where("id=".$data['dd'])->data($data)->save()){
                $this->success('修改成功',U('/lider'));
            }else{
                $this->success('修改失败',U('/lider'));
            }
        } else {
        
            $this->display();
        }
    }
    
    public  function statusAct(){
        $M=M("user");
        $data["status"]=$_GET["status"]?0:1;
        $condition["id"]=$_GET["id"];
        $M->where($condition)->save($data);
        echo "ok";
    }
        
  

}

?>